package com.smartplatform.event.listener;

import com.smartplatform.event.DeviceOnLineEvent;
import com.smartplatform.service.SysDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @Author 咕唧
 * @Date 2022/6/4 21:29
 * @Version 1.0
 * 事件 当设备状态爱发生改变时执行
 */
@Component
public class DeviceOnlineListener {
    private SysDeviceService sysDeviceService;

    @Autowired
    public void setSysDeviceService(SysDeviceService sysDeviceService) {
        this.sysDeviceService = sysDeviceService;
    }

    @Async
    @EventListener
    public void onEvent(DeviceOnLineEvent event) {
        sysDeviceService.updateDevice(event.getDeviceId(), event.getIp());
    }

}
